#include <bits/stdc++.h> 
using namespace std;

char get_num(int k) {
	int m = k * 7;
	while (m > 9) {		
		int sum = 0;
		int m1 = m;
		while (m1 > 0) {
			int t = m1 % 10;
			m1 = m1 / 10;
			sum += t;
		}		
		m = sum;
	}
	
	return m + '0';
}
bool is_lucky(string &s) {
	int len = s.length();
	int cnt = 1;
	for (int i=len - 1; i>=0; i--) {
		if (cnt % 2 == 1) {
			int k = s[i] - '0';
			s[i] = get_num(k);		
		}
		cnt ++;
	} 
	int sum = 0;
	for (int i=0; i<len; i++) {
		int k = s[i] - '0';
		sum += k;
	}
	if (sum % 8 == 0) {
		return true;
	} 
	return false;
}
int main() {
	int n;
	cin >> n;
	for (int i=0; i<n; i++) {
		string s; 
		cin >> s;
		if (is_lucky(s)) {
			cout << "T" << endl; 
		} else {
			cout << "F" << endl; 
		}
	}
	return 0;
}
